﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Models;

namespace DAL.ArtworkLike
{
    public class ArtworkLikeDao : BaseDao, IArtworkLikeDao
    {
        public bool DeleteArtworkLike(Models.ArtworkLikes artworkLike)
        {
            return db.Deleteable<Models.ArtworkLikes>().Where(artworkLike).ExecuteCommandHasChange();
        }

        public ArtworkLikes GetArtworkLikeById(int artworkId, int ownerId)
        {
            return db.Queryable<Models.ArtworkLikes>().First(it => it.ArtworkID == artworkId && it.OwnerID == ownerId);
        }

        public List<ArtworkLikes> GetListByOwnerId(ref int totalCount, int ownerId, int pageIndex = 1, int pageSize = 12, string orderBy = "CreatedAt Desc")
        {
            return db.Queryable<Models.ArtworkLikes>().Where(it=>it.OwnerID == ownerId).OrderBy(orderBy).ToPageList(pageIndex,pageSize,ref totalCount);
        }

        public void InsertArtworkLike(ArtworkLikes artworkLike)
        {
            db.Insertable<Models.ArtworkLikes>(artworkLike).ExecuteCommandIdentityIntoEntity();
        }
    }
}
